<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
    <table>
        <tr>
            <td colspan="4">
                <input id="output" type="text" disabled>
            </td>
        </tr>
        <tr>
            <td><button class="num">%</button></td>
            <td><button>CE</button></td>
            <td><button class="clear">C</button></td>
            <td><button class="num">/</button></td>
        </tr>
        <tr>
            <td><button class="num">7</button></td>
            <td><button class="num">8</button></td>
            <td><button class="num">9</button></td>
            <td><button class="num">+</button></td>
        </tr>
        <tr>
            <td><button class="num">4</button></td>
            <td><button class="num">5</button></td>
            <td><button class="num">6</button></td>
            <td><button class="num">-</button></td>
        </tr>
        <tr>
            <td><button class="num">1</button></td>
            <td><button class="num">2</button></td>
            <td><button class="num">3</button></td>
            <td><button class="num">*</button></td>
        </tr>
        <tr>
            <td><button class="num">.</button></td>
            <td><button class="num">0</button></td>
            <td colspan="2"><button style="width: 160px;" class="equal">=</button></td>
        </tr>
    </table>
</body>
<script>
    $(()=>{
        var str='';
        $($('.num').on('click',function(){
            /* 获取点击的数据 */
            var num1=$(this).text();
            str += num1
            $('#output').val(str)
        }))
        $($('.equal').on('click',function(){
            $('#output').val(eval(str))
            str=eval(str)
        }))
        $($('.clear').on('click',function(){
            str=''
            $('#output').val('')
        }))
    })
</script>
</html>